<template>
  <div class="proDetail">
    <div class="scroll">
      <div class="" v-show="isShow">
        <van-sticky>
          <div class="top">
            <van-search shape="round" background="#fff" />
          </div>
          <van-tabs v-model="active">
            <van-tab v-for="item in navlist" :title="item" :key="item"></van-tab>
          </van-tabs>
        </van-sticky>
      </div>
      <div class="topNavbar" v-show="!isShow">
        <van-nav-bar left-text="返回" left-arrow>
          <template #left>
            <van-icon name="revoke" size="30" @click="returnBack" />
          </template>
          <template #right>
            <van-icon name="search" size="30" @click="topsearch" />
            <van-icon name="share-o" size="30" />
          </template>
        </van-nav-bar>
      </div>
      <div class="swiper">
        <div id="swiperSeamlessScroll" style="position: absolute;bottom: 0;z-index: 100;overflow: hidden;">
          <vueSeamlessScroll :data="source" class="seamless-warp" :class-option="optionSingleHeightTime">
            <ul class="list" @mousemove="stopScroll" @mouseout="doScroll">
              <li :class="{ devicelistitem: true, even: (index + 1) % 2 !== 0 }" v-for="(item, index) in source"
                :key="index">
                <span :title="item">{{ item }}</span>
              </li>
            </ul>
          </vueSeamlessScroll>
        </div>
        <van-swipe :autoplay="3000">

          <van-swipe-item v-for="(item, index) in banners" :key="index">
            <img :src="item" />
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="main">
        <div class="mainPriceArea" style="height:'250px';">
          <MainPriceArea :prodetail=prodetail></MainPriceArea>
        </div>
        <div class="peisong">
          <Peisong></Peisong>
        </div>
        <div class="evaluateArea">
          <!-- <UserEvaluate :assess="assess" :counts="counts" @click="changevanPopupShow"></UserEvaluate> -->
          <div class="userEvaluate">
            <div style="display: flex;justify-content: space-between;">
              <span>用户评价（{{ counts }}）</span>
              <span @click="changevanPopupShow">全部评价></span>
            </div>
            <div style="display: flex;padding: 10px;">
              <div class="haoping">{{ goodLve }}% <br> 好评率</div>
              <div>111</div>
            </div>
            <div class="evaluate">
              <div style="display: flex;align-items: center;">
                <div class="top">
                  <img :src="evaluate.consumerImg" width="30px" height="30px">
                </div>
                <p style="flex:1;display: flex;flex-direction: column;">
                  <span style="font-size: 14px;">{{ evaluate.commentator }}</span>
                  <span style="color: rgb(187, 107, 9);">{{ evaluate.isGood == 1 ? "好评" : evaluate.isGood == 2 ? "中评" :
                    "差评"
                  }}</span>
                </p>
                <p style="font-size: 12px;">
                  {{ evaluate.replyDate }}
                </p>
              </div>
              <div>
                {{ evaluate.review }}
              </div>
              <div class="custorImgArea">
                <img v-for="(item, index) in evaluateImgs" :key="index" width="60px" height="60px" :src="item">
              </div>
            </div>
          </div>
        </div>

        <div class="proInfor">
          <ul class="proInforChild">
            <li style="color: #9d9999;">商品详情</li>
            <li>品牌 ： {{ prodetail.brand }}</li>
            <li>规格 ：{{ prodetail.specs }}</li>
            <li>产地 ：{{ prodetail.producer }}</li>
            <li>重量 ：{{ prodetail.weight }}</li>
            <li>保质期 ：{{ prodetail.expdate }}</li>
          </ul>
        </div>
        <div class="proImg">
          <img :src="prodetail.proInfoImg">
          1111111111111111
        </div>
      </div>
    </div>

    <div class="bottomCar">
      <BottomAddCar></BottomAddCar>
    </div>
    <van-popup v-model="vanPopupShow" position="bottom" :style="{ height: '100%' }">
      <AlluserEvaluate @change="changeAllEvaluates" :assess="assess" :goodLve="goodLve"></AlluserEvaluate>
    </van-popup>
  </div>
</template>

<script>
import Search_Ranking from "@/views/homes/search_Ranking.vue"
import BottomAddCar from "@/views/pro/bottomAddCar.vue"
import MainPriceArea from "@/views/pro/mainPriceArea.vue"
import Peisong from "@/views/pro/peisong.vue"
import UserEvaluate from "@/views/pro/userEvaluate.vue"
import Pro from "@/api/pro"
import AlluserEvaluate from "./alluserEvaluate.vue"
import vueSeamlessScroll from "vue-seamless-scroll";
export default {
  components: {
    vueSeamlessScroll,//滚动数据
    Search_Ranking,
    BottomAddCar,
    MainPriceArea,
    Peisong,
    UserEvaluate,
    AlluserEvaluate
  },
  data() {
    return {
      searchShow: false,//搜索遮罩层
      isShow: false,
      active: 2,
      navlist: ["商品", "评价", "菜谱", "推荐", "详情"],
      prodetail: {},
      vanPopupShow: false,
      banners: [],
      counts: 0,//用户评论总数
      assess: [],//用户评论数组
      evaluate: {},//第一条用户评论
      evaluateImgs: [],//第一条用户评论图片
      goodLve: 0,//好评率
      allowScroll: true,
      source: ["推荐商品,热销榜第一", "多人推荐，网红产品", "值得购买,质量很棒", "物美价廉"],
    }
  },
  mounted() {
    this.getProDetail1(Number(this.$route.params.productId))
  },
  computed: {
    optionSingleHeightTime() {
      return {
        singleHeight: 10,
        waitTime: 1000,
        limitMoveNum: 3,
      };
    },
  },
  methods: {
    returnBack(e) {
      this.$router.go(-1)
    },
    topsearch() {
      this.searchShow = true
    },
    changeIsshow(val) {
      this.searchShow = false
    },
    stopScroll() {
      this.allowScroll = false;
    },
    doScroll() {
      this.allowScroll = true;
    },
    async getProDetail1(productId) {
      console.log(productId)
      let res = await Pro.getProDetail({ productId })
      console.log(res.data)
      this.prodetail = res.data
      this.banners = this.prodetail.banners.split('||')
      this.counts = res.data.assess.length
      if (this.counts > 0) {
        this.assess = res.data.assess
        this.evaluate = res.data.assess[0]
        this.evaluateImgs = this.evaluate.evaluateImg.split("||")
      } else {
        this.assess =[]
        this.evaluate = []
        this.evaluateImgs = []
      }
      let goodCount = 0
      this.assess.map(item => {
        if (item.isGood === 1) {
          goodCount += 1
        }
      })
      if (goodCount == 0) {
        this.goodLve = 0
      } else {
        this.goodLve = Number((goodCount / this.assess.length).toFixed(2)) * 100
      }

    },
    changeAllEvaluates() {
      this.vanPopupShow = false
    },
    changevanPopupShow() {//改变弹出层的状态
      this.vanPopupShow = true
    }

  }
}
</script>

<style scoped lang="scss">
.topNavbar {
  position: fixed;
  background: none;
  z-index: 10;

  .van-icon {
    color: #000;
  }

}

.seamless-warp>span {
  height: 40px;
  padding: 10px;
}

.proDetail {
  height: 100%;
  width: 100%;

  .scroll {
    // overflow: scroll;

    .swiper {
      width: 100%;
      height: 5%;
      position: relative;
      ;

      .swiperSeamlessScroll {
        position: absolute;
        left: 10px;
        bottom: 0;
        background: yellow;
        width: 40vw;
        height: 10vh
      }

      .van-swipe-item {
        width: 100%;
        height: 30%;
      }

      img {
        width: 100%;
        height: 300px;
      }
    }

    .main {
      background: #eee;
      height: 1000px;
      box-sizing: border-box;
      padding-left: 10px;
      padding-right: 10px;
      padding-top: 10px;

      .mainPriceArea {
        height: 200px;
        margin-bottom: 10px;
      }

      .peisong {
        height: 80px;
        width: 100%;
        margin-bottom: 10px;
      }

      .evaluateArea {
        // height: 250px;
        width: 100%;
        margin-bottom: 10px;
      }

      .proInfor {
        width: 100%;

        .proInforChild {
          background: #fff;
          padding: 10px;
          box-sizing: border-box;
          border-radius: 10px;
          margin-bottom: 10px;

          li {
            border-bottom: 1px solid #cec9c9;
            height: 30px;
            line-height: 30px;
          }

          li:nth-last-child(1) {
            border-bottom: none
          }
        }
      }

      .proImg {
        width: 100%;

        img {
          width: 100%;
        }
      }

      .l_mido {
        margin-left: 5px;
      }



      ._bangdan {
        padding: 2px 4px;
        color: burlywood;
        border-radius: 9px;
        font-size: 16px;
        background: yellow;
      }

      .par_bangdan {
        background: rgba($color: yellow, $alpha: .3);

      }
    }
  }

  .topNavbar {


    .van-icon {
      margin-right: 15px;

    }
  }



  .userEvaluate {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    box-sizing: border-box;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 10px;

    .haoping {
      color: rgb(114, 229, 191);
      border-right: 2px solid #625c5c;
      width: 80px;
      font-size: 18px;
      font-weight: bold;
      border-right: 1px solid #eee;
    }

    .evaluate {
      width: 96%;
      margin: 0 auto;
      height: 50%;
      background: #eee;
      border-radius: 10px;
      box-sizing: border-box;
      padding: 10px;

      .top {
        overflow: hidden;
        width: 30px;
        height: 30px;
        border-radius: 30px;
        margin-right: 10px;
      }

      .custorImgArea {
        overflow: scroll;
        display: flex;
        justify-content: space-evenly;

        img {
          margin: 10px;
        }
      }
    }
  }
}

.bottomCar {
  position: fixed;
  bottom: 0;
  height: 50px;
  width: 100%;
  background: #fff;
  border-top-left-radius: 30px;
  border-top-right-radius: 30px;
}

.seamless-warp {
  height: 80px;
  padding-left: 10px;
}
</style>
